/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.product.entity.SpecificationInventory
   Module Description   :

   Date Created      : 2009/11/24
   Original Author   : ellen.li
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.product.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.yaodian100.core.common.entity.BaseEntity;

/**
 * @author ellen.li 商品規格之庫存相關資訊
 */
@Entity
@Table(name = "EC_SPECIFICATION_INVENTORY")
public class SpecificationInventory extends BaseEntity {

	/** serial version */
	private static final long serialVersionUID = -8631858709368683189L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_ec_specificationinventory")
	@SequenceGenerator(name = "seq_ec_specificationinventory", sequenceName = "SEQ_EC_SPECIFICATIONINVENTORY")
	@Column(name = "ID")
	private Long id;

	@Column(name = "SPEC_ID", updatable = false)
	private Long specId;

	@ManyToOne
	@JoinColumn(name = "SPEC_ID", insertable = false, updatable = false)
	@NotFound(action = NotFoundAction.IGNORE)
	@LazyToOne(LazyToOneOption.FALSE)
	private Specification specification;

	@Column(name = "PRODUCT_ID", updatable = false)
	private String productId;

	/** 可售數 */
	@Column(name = "AVAILABLE_INVENTORY")
	private int availableInventory;

	/** 訂購數 */
	@Column(name = "SOLD_INVENTORY")
	private int soldInventory;

	/** 取消數 */
	@Column(name = "CANCEL_INVENTORY")
	private int cancelInventory;

	/**
	 * @return the availableInventory
	 */
	public int getAvailableInventory() {
		return availableInventory;
	}

	/**
	 * @return the cancelInventory
	 */
	public int getCancelInventory() {
		return cancelInventory;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	@Transient
	public Integer getInventory() {
		int inventory = availableInventory - soldInventory + cancelInventory;
		if (inventory < 0) {
			inventory = 0;
		}
		return inventory;
	}

	/**
	 * @return the productId
	 */
	public String getProductId() {
		return productId;
	}

	/**
	 * @return the soldInventory
	 */
	public int getSoldInventory() {
		return soldInventory;
	}

	/**
	 * @return the specId
	 */
	public Long getSpecId() {
		return specId;
	}

	/**
	 * @return the specification
	 */
	public Specification getSpecification() {
		return specification;
	}

	/**
	 * @param availableInventory the availableInventory to set
	 */
	public void setAvailableInventory(int availableInventory) {
		this.availableInventory = availableInventory;
	}

	/**
	 * @param cancelInventory the cancelInventory to set
	 */
	public void setCancelInventory(int cancelInventory) {
		this.cancelInventory = cancelInventory;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param productId the productId to set
	 */
	public void setProductId(String productId) {
		this.productId = productId;
	}

	/**
	 * @param soldInventory the soldInventory to set
	 */
	public void setSoldInventory(int soldInventory) {
		this.soldInventory = soldInventory;
	}

	/**
	 * @param specId the specId to set
	 */
	public void setSpecId(Long specId) {
		this.specId = specId;
	}

	/**
	 * @param specification the specification to set
	 */
	public void setSpecification(Specification specification) {
		this.specification = specification;
	}

}
